package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.crm.entity.BsNodeEqpt;
@Mapper
public interface BsNodeEqptMapper {

	@Insert("insert into bs_eqpt_info(node_id, eqpt_id, uses_address, post_address, contact_name, "
			+ "contact_phone, manage_ip, begin_date, end_date, update_time, update_user,province,city)"
			+ " values(#{nodeId}, #{eqptId}, #{usesAddress},#{postAddress}, #{contactName},"
			+ " #{contactPhone}, #{manageIp}, #{beginDate}, #{endDate}, #{updateTime}, #{updateUser}, #{province}, #{city})")
	int insertNodeEqpt(BsNodeEqpt eqpt);

	@Update("update bs_eqpt_info set uses_address=#{usesAddress},post_address=#{postAddress},contact_name=#{contactName},contact_phone=#{contactPhone},"
			+ "manage_ip=#{manageIp},end_date=#{endDate},update_time=#{updateTime},update_user=#{updateUser},province=#{province},city=#{city} "
			+ " where eqpt_id=#{eqptId} and begin_date=#{beginDate}")
	int updateNodeEqpt(BsNodeEqpt eqpt);

	@Select(value = { "select * from bs_eqpt_info where eqpt_id = #{eqptId} and now() between begin_date and end_date" })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "eqpt_id", property = "eqptId"),
			@Result(column = "uses_address", property = "usesAddress"),@Result(column = "contact_name", property = "contactName"),
			@Result(column="contact_phone",property="contactPhone"),@Result(column="manage_ip",property="manageIp"),
			@Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
			@Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
			@Result(column = "post_address", property = "postAddress"),
			@Result(column="province",property="province"),@Result(column="city",property="city")
	})
	public BsNodeEqpt getNodeEqptInfoByPk(Long equip_id);
	
	@Select(value = { "select * from bs_eqpt_info where node_id = #{nodeId} and now() between begin_date and end_date" })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "eqpt_id", property = "eqptId"),
			@Result(column = "uses_address", property = "usesAddress"),@Result(column = "contact_name", property = "contactName"),
			@Result(column="contact_phone",property="contactPhone"),@Result(column="manage_ip",property="manageIp"),
			@Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
			@Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
			@Result(column = "post_address", property = "postAddress"),
			@Result(column="province",property="province"),@Result(column="city",property="city")})
	public List<BsNodeEqpt> getNodeEqptsByNodeId(Long nodeId);

	@Select(value = { "select * from bs_o_work_eqpt where node_id = #{nodeId} and now() between begin_date and end_date" })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "eqpt_id", property = "eqptId"),
			@Result(column = "uses_address", property = "usesAddress"),@Result(column = "contact_name", property = "contactName"),
			@Result(column="contact_phone",property="contactPhone"),@Result(column="manage_ip",property="manageIp"),
			@Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
			@Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
			@Result(column="work_id",property="workId"),@Result(column="modify_tag",property="modifyTag"),
			@Result(column = "post_address", property = "postAddress"),
			@Result(column="province",property="province"),@Result(column="city",property="city")})
	public List<BsNodeEqpt> getBsNodeEqptsByNodeId(Long nodeId);
}
